import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

Vue.config.productionTip = false;

// 引入element-ui
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);

/** -------------- axios -------------------- */
// 引入axios
import axios from 'axios'
Vue.prototype.$axios = axios 

// 拦截请求
axios.interceptors.request.use((config) => {
  console.info("请求拦截",config);
  // 请求拦截
  
  return config;
});

// 拦截响应
axios.defaults.crossDomain = true;
axios.interceptors.response.use((response) => {
  console.log('响应',response);
  if (response && response.data) {
    if (response.data.status == "UNKNOWN" || response.status == 302) {
      alert("passport登录超时，刷新重新登录");
      window.location.reload();
    } else {
      return response;
    }
  } else {
    return response;
  }
}, function (error) {
  console.error('拦截error',error);
  router.push('/404')
});
axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';


/** ---------------- axios end------------------ */

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
